from django.contrib import admin
from django.conf import settings
from django.apps import apps
from .models import (Article,
                     Tag,
                     Concept,
                     ArticleToTag,
                     Point)

# 自定义管理站点的名称和URL标题
admin.site.site_header = '网站管理'
admin.site.site_title = '后台管理'


@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
    # 这个的作用是给出一个筛选机制，一般按照时间比较好
    date_hierarchy = 'create_date'

    list_per_page = 50  # 控制每页显示的对象数量，默认是100

    # 激活过滤器，这个很有用
    list_filter = ('create_date',)

    # 在查看修改的时候显示的属性，第一个字段带有<a>标签，所以最好放标题
    list_display = ('id', 'title', 'author', 'create_date', 'update_date')

    # 设置需要添加<a>标签的字段
    list_display_links = ('title',)

    # filter_horizontal = ('tags',)  # 给多选增加一个左右添加的框

    search_fields = ('title',)


@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
    search_fields = ("title",)

    list_per_page = 50


@admin.register(Concept)
class ConceptAdmin(admin.ModelAdmin):
    search_fields = ("name",)

    list_per_page = 50


@admin.register(Point)
class PointAdmin(admin.ModelAdmin):
    search_fields = ("context",)

    list_per_page = 50


@admin.register(ArticleToTag)
class ArticleToTagAdmin(admin.ModelAdmin):
    list_per_page = 50

# @admin.register(PointToConcept)
# class PointToConcept(admin.ModelAdmin):
#     search_fields = ("point",)
#
#     list_per_page = 50
